<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    body{
      margin: 0;
    }
    #box{
      width: 100vw;
      height: 100vh;
    }
  </style>
</head>
<body>
<div id="box">
  <input type="text">

  <div style="height: 3300px"></div>

  <div id="son">son</div>
</div>
<script>
  son.addEventListener('mousedown',(e)=>{
    console.log('e.clientX:',e.clientX);
    console.log('e.clientY:',e.clientY);
    console.log('e.screenX:',e.screenX);
    console.log('e.screenY:',e.screenY);
    console.log('e.pageX:',e.pageX);
    console.log('e.pageY:',e.pageY);
  })

  //左键 中健 右键
  window.addEventListener('mousedown',(e)=>{
    console.log('mousedown e:',e)
    console.log('e.button:',e.button)
    //0 是左键
    //1 是中键
    //2 是右键

    console.log('e.clientX:',e.clientX); //相对于浏览器
    console.log('e.clientY:',e.clientY);
    console.log('e.screenX:',e.screenX); //相对于整个pc屏幕
    console.log('e.screenY:',e.screenY);
    console.log('e.pageX:',e.pageX);     //相对于浏览器(但要包含滚动的距离,client系列则不会包含)
    console.log('e.pageY:',e.pageY);
  })
  window.addEventListener('mouseup',(e)=>{
    console.log('mouseup e:',e)
    console.log('e.button:',e.button) //通mousedown
  })
  //click 只有左键点击会触发(而mousedown和mouseup不论左键中键还是右键都会触发)
  //, 且晚于mouseup触发
  window.addEventListener('click',(e)=>{
    console.log('click e:',e)
    console.log('e.type:',e.type);
    console.log('e.button:',e.button)
  })
  /*这几个点击事件触发顺序依次为
    1. mousedown
    2. mouseup
    3. click
    4. mousedown
    5. mouseup
    6. click
    7. dblclick
  */


  //鼠标左键双击事件
  window.addEventListener('dblclick'/*← 注意这里有一个 'l' */,(e)=>{
    console.log('dblclick e:',e)
    console.log('e.type:',e.type);
    console.log('e.button:',e.button)
  })
  //todo 怎么不直接用dblclick 而是用mousedown、mouseup、click去模拟, 这应用场景在于远程通信的一些项目中 (如果我们监听了dbclick,但之前若监听了mouseup什么的,那相当于会多发送一次dbclick给远程, 而如果我们用模拟的, 那么在mouseup里就直接包含了dbclick, 如果识别到是dbclick, 我们就不用把两次mouseup发过去, 而是直接发送一个dbclick即可)

</script>
</body>
</html>
